package com.chookss.home.audit;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chookss.R;
import com.chookss.Urls;
import com.chookss.base.StaticClass;
import com.chookss.tools.FileUtilss;
import com.chookss.tools.GlideUtils;
import com.chookss.tools.NavigationTools;
import com.chookss.tools.Utils;
import com.chookss.wxapi.WeChatShareUtil;
import com.johnrambo.ktea.ktExtends.ShareUtils;
import com.lvgroup.hospital.base.BaseAct;

import org.jetbrains.annotations.Nullable;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WorkCardActivity extends BaseAct {

    @BindView(R.id.tvTime)
    TextView tvTime;
    @BindView(R.id.ivLogo)
    ImageView ivLogo;
    @BindView(R.id.ivHead)
    ImageView ivHead;
    @BindView(R.id.tvName)
    TextView tvName;
    @BindView(R.id.tvPost)
    TextView tvPost;
    @BindView(R.id.tvNum)
    TextView tvNum;
    @BindView(R.id.tvGroup)
    TextView tvGroup;
    @BindView(R.id.rlContent)
    RelativeLayout rlContent;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_work_card);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        initState();
        NavigationTools.saveUseRecord(this, "1", "29");
        if (getPackageName().equals("com.zhaofengnum")) {
            ivLogo.setBackgroundResource(R.drawable.zhaofeng_qy_logo);
        } else {
            ivLogo.setBackgroundResource(R.drawable.qy_logo);
        }
        tvName.setText(new ShareUtils().getString(this, StaticClass.USER_NICKNAME, ""));
        tvPost.setText(new ShareUtils().getString(this, StaticClass.POST, ""));
        tvNum.setText("NO." + new ShareUtils().getString(this, StaticClass.EMPLOYEECODE, ""));
        tvGroup.setText(new ShareUtils().getString(this, StaticClass.BELG_ORG_NAME, ""));
        GlideUtils.loadAvatar(this, new ShareUtils().getString(this, StaticClass.ORIGINALURL, ""), ivHead);
//        GlideUtils.loadAvatar(this,"https://img1.baidu.com/it/u=1573749468,2546811405&fm=253&fmt=auto&app=138&f=JPEG?w=200F&h=200",ivHead);
        tvTime.setText(Utils.getCurrentTime3());
    }

    private void toShare() {
        rlContent.setDrawingCacheEnabled(true);
        Bitmap bitmap = rlContent.getDrawingCache();
        String name=getExternalFilesDir(Urls.IMAGEFOLDER).getAbsolutePath() + File.separator + System.currentTimeMillis()+".jpg";
        FileUtilss.saveBitmap2(bitmap,name);
        WeChatShareUtil.getInstance(this).imageShare(name, "jpg", FileUtilss.getFileSize(new File(name)));
    }

    @OnClick({R.id.common_title_back, R.id.common_right_iv_ll})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.common_title_back:
                finish();
                break;
            case R.id.common_right_iv_ll:
                toShare();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(rlContent!=null){
            //回收资源
            rlContent.setDrawingCacheEnabled(false);
            rlContent.destroyDrawingCache();
        }
    }
}
